<#include "../common/com.html"/> <@layout>

<!-- ace styles -->
<link rel="stylesheet" href="${ctx}/static/assets/css/ace.min.css" />
<script src="${ctx}/static/inc/platform/js/ajax.js"></script>

<script type="text/javascript">
    function xfkd() {
        var card =$("#cards").val();
        $("#id").attr("value", $("#ids").val());
        var id = $("#id").val();
        var url = '${ctx}/xskd/xskd?id=' + id+"&card="+card;
        window.location.href = url;
    }


</script>
<div class="page-content">
    <div class="page-header" style="height: 15px">结账收银</div>
    <!-- /.page-header -->
    <div class="row-fluid">
        <div class="span12 ">
            <div class="widget-main alert-info">
                请输入会员信息：<input id="card" name="card" type="text"
                               style="min-height: 24px;" />
                <button id="search_btn" onclick="return true;"
                        class="btn btn-info btn-small" >查询</button>
            </div>



            <div id="divs"></div>
            <form class="form-inline" id="myform">
                <input id="ida" name="ida" type="hidden"  />
                <input type="hidden" name="vipcard" id="vipcard"  >
                <input type="hidden" name="moneys" id="moneys"  >
                <input type="hidden" name="cards" id="cards" >
                <input type="hidden" name="xfsjjga" id="xfsjjga">
                <input type="hidden" name="ye" id="ye" value=" ${(m.ye)!}" >
            </form>

        </div>
    </div>
</div>
</body>

<script>
    $("#search_btn").click(
            function() {
                var card = $("#card").val();
                send_request_update('${ctx}/hyglXf/xfjz?card=' + card,
                        "", divs);
            });

    jQuery(function($) {

        var cards = '${(card)!}';
        if (cards != "") {
            send_request_update('${ctx}/hyglXf/xfjz?card=' + cards,
                    "", divs);
        }
    });
    // 绑定回车事件
    document.onkeydown = function(e)
    {
        var e = window.event   ?   window.event   :   e;
        if(e.keyCode == 13){
            var card = $("#card").val();
            send_request_update('${ctx}/hyglXf/xfjz?card=' + card,
                    "", divs);
        }
    }

    function selectAll(obj_name) {
        var objs = document.getElementsByName(obj_name);
        var obja = document.getElementsByName("xfsjjgs");
        if (objs) {
            var je=0;
            for (i = 0; i < objs.length; i++) {
                if (!objs[i].disabled)
                    objs[i].checked = !objs[i].checked;
            }
            for(i=0;i<objs.length;i++){
                var jes= "";
                if(objs[i].checked){
                     jes= obja[i].value;
                  je+=  parseFloat(jes);
                }  else {
                     jes= 0;
                    je+=  parseFloat(jes);
                }
                $("#ysje").html(toDecimal(je)) ;
                $("#xfsjjga").attr("value",toDecimal(je)) ;
            }
         }
    }

    function selectxf(obj){
        var objs = document.getElementsByName(obj);
        var obja = document.getElementsByName("xfsjjgs");
        if (objs) {
            var je=0;
        for(i=0;i<objs.length;i++){
            var jes= "";
            if(objs[i].checked){
                jes= obja[i].value;
                je+=  parseFloat(jes);
            }  else {
                jes= 0;
                je+=  parseFloat(jes);
            }
            $("#ysje").html(toDecimal(je)) ;
            $("#xfsjjga").attr("value",toDecimal(je)) ;
        }
        }
    }

    function toDecimal(x) {
        var f = parseFloat(x);
        if (isNaN(f)) {
            return false;
        }
        var f = Math.round(x*100)/100;
        var s = f.toString();
        var rs = s.indexOf('.');
        if (rs < 0) {
            rs = s.length;
            s += '.';
        }
        while (s.length <= rs + 2) {
            s += '0';
        }
        return s;
    }

    function checkAdd(){
        var cd=document.getElementsByName("id");
        var m =0;
        for(var i=0;i<cd.length;i++){
            if(cd[i].type.toLowerCase()=="checkbox"){
                if(cd[i].checked==true && cd[i].id != 'checkAll'){
                    m =m+1;
                }
            }
        }
        if (m==0){
            alert('请选择要结账的消费!');
            return ;
        }
        selectxf('id');
        var objs = document.getElementsByName("id");
        var id="";

        if (objs) {
            for(i=0;i<objs.length;i++){
                if(objs[i].checked){
                    id+= objs[i].value+",";
                }
            }
        }
        if($("#vipcarda").val()=="" && $("#moneysa").val() ==""){
            alert("卡消费现金不能都为空！");
            return;
        }
        var url = '${ctx}/hyglXf/save';

        $("#ida").attr("value",id.substr(0,id.length-1));
        $("#vipcard").attr("value",$("#vipcarda").val());
        $("#moneys").attr("value",$("#moneysa").val());
        $("#cards").attr("value",$("#carda").val());
        $("#ye").attr("value",$("#yea").val());
        if(confirm("您确认要结账吗？")){
            $('#myform').form('submit', {
                url : url,
                onSubmit : function() {
                    return $(this).form('validate');
                },
                success : function(data) {
                    if(data!="0"){
                        alert("结账成功！");
                        var card = $("#card").val();
                        send_request_update('${ctx}/hyglXf/xfjz?card=' + card,
                                "", divs);
                    }     else{
                    }
                }
            });
        }
    }

    function gs(){
        var cd=document.getElementsByName("id");
        var m =0;
        for(var i=0;i<cd.length;i++){
            if(cd[i].type.toLowerCase()=="checkbox"){
                if(cd[i].checked==true && cd[i].id != 'checkAll'){
                    m =m+1;
                }
            }
        }
        if (m==0){
            alert('请选择要删除的消费!');
            return ;
        }
        var objs = document.getElementsByName("id");
        var id="";

        if (objs) {
            for(i=0;i<objs.length;i++){
                if(objs[i].checked){
                    id+= objs[i].value+",";
                }
            }
        }

        var url = '${ctx}/hyglXf/delete';

        $("#ida").attr("value",id.substr(0,id.length-1));
        $("#cards").attr("value",$("#carda").val());
        if(confirm("您确认要删除此订单吗？")){
            $('#myform').form('submit', {
                url : url,
                onSubmit : function() {
                    return $(this).form('validate');
                },
                success : function(data) {
                    if(data!="0"){
                        alert("删除成功！");
                        var card = $("#card").val();
                        send_request_update('${ctx}/hyglXf/xfjz?card=' + card,
                                "", divs);
                    }     else{
                    }
                }
            });
        }
    }
</script>
</@layout>
